package util

import (
	"fmt"
	"time"
)

var LayoutDateTime = "2006-01-02 15:04:05"
var LayoutDate = "2006-01-02"

func ComputeTime(startTime, endTime string) []string {
	var res []string
	layout := "2006-01-02"
	// 2018-06-01  2018-12-31
	//time1, err := time.Parse(layout, "2017-01-01")
	time1, err := time.Parse(layout, startTime)
	//time2, err := time.Parse(layout, "2017-12-31")
	time2, err := time.Parse(layout, endTime)
	if err != nil {
		fmt.Println(err)
	}
	subM := time2.Sub(time1)
	//fmt.Println(subM.Hours() / 24)
	a := subM.Hours() / 24
	for i := 0; i <= int(a); i++ {
		if d, err := time.ParseDuration(fmt.Sprintf("%vh", 24*i)); err == nil {
			res = append(res, time1.Add(d).Format(layout))
		}
	}
	return res
}
